package lgkj.meicqt20.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import lgkj.meicqt20.R;
import lgkj.meicqt20.bean.TrainEnitity;
import lgkj.meicqt20.utils.CommUtils;

/**
 * Created by Administrator on 2018/4/23 0023.
 */

public class CollegeNewAdapter extends BaseAdapter {
    private static final String TAG = "CollegeNewAdapter";
    private Context context;

    private List<TrainEnitity.DataBean> data;
    private int position = -1;


    public void setPosition(int position) {
        this.position = position;
    }

    public void setData(TrainEnitity dataBeen) {
        if (dataBeen != null) {
//            if (dataBeen.getData() != null)
            this.data = dataBeen.getData();
//            else
//                this.data.clear();
        } else {
            this.data.clear();
        }
        Log.i(TAG, "setData: " + data.size());
    }


    public CollegeNewAdapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    public TrainEnitity.DataBean getData(int i) {
        return data.get(i);
    }


    @Override
    public long getItemId(int i) {
        return i;
    }


    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holer viewHolder = null;
        if (view == null) {
            viewHolder = new Holer();
            view = LayoutInflater.from(context).inflate(R.layout.item_college, null);
            viewHolder.video_one = (ImageView) view.findViewById(R.id.video_one);
            viewHolder.video_pic = (ImageView) view.findViewById(R.id.video_pic);
            viewHolder.video_name = (TextView) view.findViewById(R.id.video_name);
            view.setTag(viewHolder);
        } else {
            viewHolder = (Holer) view.getTag();
        }
        String url = "";
        String name = "测试";
        url = data.get(i).getImg();
        name = data.get(i).getTitle();
        viewHolder.video_name.setText(name);
        CommUtils.LoadImage(context, viewHolder.video_pic, url, R.mipmap.common_icon_err);
        if (position == i) {
            viewHolder.video_one.setBackgroundResource(R.mipmap.yxzxyxbk);
        } else {
            viewHolder.video_one.setBackgroundResource(0);
        }
        return view;
    }

    class Holer {
        ImageView video_one;
        ImageView video_pic;
        TextView video_name;
    }
}
